package com.cloud.wms.ui.in.presnter;


import com.cloud.core.base.BaseRxPresenter;
import com.cloud.core.utils.MessageCreator;
import com.cloud.wms.app.FineExApplication;
import com.cloud.wms.http.Params;
import com.cloud.wms.http.observer.LoadingObserver;
import com.cloud.wms.http.observer.ResponseWrapper;
import com.cloud.wms.tools.RxUtils;
import com.cloud.wms.ui.in.contract.InContract;
import com.cloud.wms.ui.in.entity.InOrderEntity;
import com.cloud.wms.ui.in.entity.TaskDetailEntity;
import com.cloud.wms.ui.main.entity.TaskEntity;

import javax.inject.Inject;

/**
 * @Author:Chen
 * @Date: 2021-01-14 15:51
 * @Description:
 */
public class InPresenter extends BaseRxPresenter<InContract.View> implements InContract.Presenter {
    public static final int IN_DETAIL = 0x104;
    public static final int IN_ORDER = 0x102;

    @Inject
    public InPresenter() {

    }

    @Override
    public void loadInDetail(TaskEntity taskEntity) {
        Params params = new Params();
        params.put("taskId", taskEntity.getTaskID());
        FineExApplication
                .component()
                .http()
                .loadInDetail(params)
                .map(new ResponseWrapper<>())
                .compose(mView.toLifecycle())
                .compose(RxUtils.threadSwitch())
                .subscribe(new LoadingObserver<TaskDetailEntity>(mView.provideContext()) {
                    @Override
                    public void onSuccess(TaskDetailEntity info) {
                        mView.onSuccess(MessageCreator.createMessage(info, IN_DETAIL));
                    }

                    @Override
                    public void onError(String msg) {
                        mView.error(msg);
                        mView.showError();
                    }
                });
    }
}
